namespace ScrumSprintMonitor.Wpf.Application
{
	#region #using Directives

	using Extensibility;

	using Implementation;

	using Infrastructure;

	using Ninject.Core;
	using Ninject.Core.Behavior;
	using Ninject.Integration.Log4net;
	using Ninject.Integration.Log4net.Infrastructure;

	#endregion

	internal class NinjectAppRuntimeModule : Log4netModule
	{
		/// <summary>
		/// Loads the module into the kernel.
		/// </summary>
		public override void Load()
		{
			base.Load();

			Bind<IKernel>().ToConstant(Kernel);
			Bind(typeof(ILogger<>)).To(typeof(GenericLogger<>));
			Bind(typeof(IAddInHost<>)).To(typeof(AddInHost<>));

			SetupRuntimeBindings();
		}

		private void SetupRuntimeBindings()
		{
			Bind<IResourceManager>().To<ResourceManager>().Using<SingletonBehavior>();

			Bind<IProcessTemplateAdapterProvider>().To<MefProcessTemplateAdapterProvider>().Using<SingletonBehavior>();
			Bind<IConnectionProvider>().To<ConnectionProvider>().Using<SingletonBehavior>();
			Bind<IAvatarProviderStore>().To<AvatarProviderStore>().Using<SingletonBehavior>();
		}
	}

	internal class GenericLogger<T> : Log4netLogger,
	                                  ILogger<T>
	{
		public GenericLogger()
			: base(typeof(T))
		{
		}
	}
}